package com.toy.core.dao;

import java.io.InputStream;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;

import com.mongodb.gridfs.GridFSDBFile;
import com.toy.core.dao.support.Page;

public interface MongoCrudRepository<T, ID extends Serializable> {
	
	public T save(T entity);
	
	public List<T> save(List<? extends T> entities);
	
	/*------------------------------------------*/
	public T update(ID id,String propertyName,Object newValue);
	
	public T findAndModify(long idValue,Update update);
	
	public T findAndModify(String keyName,Object keyValue,Update update);
	
	public T findAndModify(List<Criteria> criteries,Update update);
	
	/*------------------------------------------*/
	public boolean isUnique(Object entity,String uniquePropertyNames);
	
	public boolean isUnique(Map<String,Object> uniqueProperties,ID id);
	
	/*------------------------------------------*/
	public T getById(ID id);
	
	public T getUniqueByProperty(String propertyName,Object value);
	
	public T getUniqueByCriteria(final Criteria... criterions);
	
	/*------------------------------------------*/
	public List<T> findAll();
	
	public List<T> findByIds(List<ID> ids);
	
	public List<T> findByProperty(String propertyName,Object value);
	
	public List<T> findByProperty(String propertyName, Object value,String orderBy, boolean isAsc);
	
	public List<T> findByCriteria(List<Criteria> criterions);
	
	public List<T> findByCriterion(List<Criteria> criterions, String orderBy,boolean isAsc);
	
	/*------------------------------------------*/
	public Page<T> findPaged(int pageNo, int pageSize);
	
	public Page<T> findPaged(Query query,int pageNo, int pageSize);
	
	public Page<T> findPaged(List<Criteria> criterions, String orderBy,boolean isAsc,int pageNo, int pageSize);
	
	/*------------------------------------------*/
	public void delete(ID id);
	
	public void delete(T entity);
	
	public void delete(List<? extends T> entities);
	
	public void deleteAll();
	
	public void deleteByProperty(String propertyName, Object value);
	
	/*---------------------GridFS操作---------------------*/
	public String saveGridFS(final InputStream is,final String fileName);
	
	public GridFSDBFile getGridFSDBFileByObjectId(final String objectId);
	
	public Map<String,GridFSDBFile> findGridFSDBFile(List<String> idList);
	
	public void deleteGridFS(final String objectId);
	
	/*---------------------辅助方法---------------------*/
	public Class<T> getEntityClass();
	
	public String getIdName();
}
